import { Behaviour } from "./engine/Behaviour";
import { Serialized } from "./engine/Serialized";
import { Live } from "./Live";
import { Score } from "./Score";

export class LifeCollider extends Behaviour {

    isDelete = false
    @Serialized('numberInput')
    money: number = 0
    isTurn = false

    onSensor() {
        
       
        const Role = this.engine.getGameObject('player')
        //  console.log(123)
        //  console.log(78)
        if (this.gameObject.id == "obstacle") {
          
           
          
            Role.getBehaviour(Live).life -= 1
    //  console.log(123)
    //         console.log(78)   
         }



        if (this.gameObject.id == "reward") {
            Role.getBehaviour(Score).point += this.money
            this.isDelete = true

        }
        if (this.gameObject.id == "door") {
            const sceneRootGameObject = this.engine.getGameObject('sceneRoot');
            const prefabGameObject = this.engine.createPrefab("win.json");
            sceneRootGameObject.addChild(prefabGameObject);
            this.isTurn = true

        }
    }
    onUpdate() {

        if (this.isDelete) {
            const sparten = this.gameObject.parent
            sparten.removeChild(this.gameObject)
        }
        if (this.isTurn) {
            const sceneRootGameObject = this.engine.getGameObject('sceneRoot');
            const backGroundObject = this.gameObject.parent
            const prefabGameObject = backGroundObject.parent
            sceneRootGameObject.removeChild(prefabGameObject);
        }
    }
}